﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace AMVCommander
{
    public partial class FormSettings : Form
    {
        public FormSettings()
        {
            InitializeComponent();
        }

        private void btnOpnPlayer_Click(object sender, EventArgs e)
        {
            opn.InitialDirectory = "";
            opn.Filter = "*.exe|*.exe";
            if(txbPlayer.Text!="")
                if (File.Exists(txbPlayer.Text))
                {
                    opn.InitialDirectory = new FileInfo(txbPlayer.Text).Directory.FullName;
                }
            if (opn.ShowDialog() == DialogResult.OK)
            {
                txbPlayer.Text = opn.FileName;
            }
        }

        private void FormSettings_Shown(object sender, EventArgs e)
        {
            // заполнение полей
            lbCols.Clear();
            for (int i = 1; i < Gl.Sett.ClmL.Count; i++)
            {
                lbCols.Add(Gl.Sett.ClmL[i].Name, Gl.Sett.ClmL[i].Visible);
                lbCols.Itm[lbCols.Itm.Count - 1].Tag = i;
            }
            lbCols.Refresh();

            txbPlayer.Text = Gl.Sett.FPathPlayer;
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            List<Column> ClmL = new List<Column>();
            Column clm = new Column(Gl.Sett.ClmL[0].Tp, Gl.Sett.ClmL[0].Width, true);
            clm.Flt = Gl.Sett.ClmL[0].Flt;
            ClmL.Add(clm);

            for (int i = 0; i < lbCols.Count; i++)
            {
                Column oldClm = Gl.Sett.ClmL[lbCols.Itm[i].Tag];
                clm = new Column(oldClm.Tp, oldClm.Width, lbCols.Itm[i].Checked);
                clm.Flt = oldClm.Flt;
                ClmL.Add(clm);
            }
            Gl.Sett.ClmL = ClmL;

            Gl.Sett.FPathPlayer = txbPlayer.Text;
           
            Gl.Sett.Save();
            Close();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            Close();
        }

               
    }
}
